VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClsCobrador"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'Clase Cobrador

Public WithEvents orset As ClsRecordset
Attribute orset.VB_VarHelpID = -1

Public Event DataChanged()

'Miembros de la Clase
Public codigo As String '
Public nombre As String 'Nombre corto del cobrador, para referencia rapida
Public estado As String 'Estado de habiltado o no

' Constructor y Destructor
Private Sub Class_Initialize()
    Set orset = New ClsRecordset
    orset.setCampos dbCampos(cob)
    orset.setTablas Array(cob)
End Sub
Private Sub Class_Terminate()
    Set orset = Nothing
End Sub
' Generic Data management methods
Public Sub consulta(Optional optHabil As String = "", Optional incluirSinCobrador As Boolean = False)
    Dim conds As Variant
    If optHabil <> "" Then
        conds = concatenaVectores(conds, Array(cob_estado & "=" & formatBoolBD(optHabil)))
    End If
    If Not incluirSinCobrador Then
        conds = concatenaVectores(conds, Array(cob_id & ">0"))
    End If
    orset.consulta conds
End Sub
Public Sub consultaDatos(codig As String)
    orset.consulta Array(cob_id & "=" & codig)
    orset.CierraRec
End Sub
Public Sub consultaDeCliente(clicod As String)
    'primero busca si el cliente tiene un cobrador en especifico
    orset.consultaGral , Array(cob, cli), _
                       Array(cob_id & "=" & cli_cob_id, _
                             cli_id & "='" & clicod & "'")
End Sub

Private Sub Reload_members()
    With orset
        codigo = .getDato(cob_id)
        nombre = .getDato(cob_nombre)
        estado = .getDato(cob_estado)
    End With
    RaiseEvent DataChanged
End Sub

Public Sub Nuevo(newNombre As String, newEstado As String)
    orset.sInsert Array("", newNombre, newEstado)
End Sub
Public Sub Modificar(codig As String, newNombre As String, newEstado As String)
    orset.sUpdate Array(codig, newNombre, newEstado)
End Sub
Public Sub Borrar(codig As String)
    orset.sDelete Array(cob_id & "=" & codig)
End Sub
'metodos de llenado
Public Sub llenaCombo(cajaCombo As ComboBox, conCodigo As Boolean, Optional optHabil As String = "", Optional sinCobrador As Boolean = False)
    Dim i As Integer
    Me.consulta optHabil, sinCobrador
    i = 0
    cajaCombo.Clear
    If conCodigo Then
        While orset.CanMoveNext
            cajaCombo.AddItem codigo & " - " & nombre
            cajaCombo.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    Else
        While orset.CanMoveNext
            cajaCombo.AddItem nombre
            cajaCombo.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    End If
    If cajaCombo.ListCount > 0 Then
        cajaCombo.ListIndex = 0
    End If
    orset.CierraRec
End Sub
Public Sub llenaList(cajaList As ListBox, conCodigo As Boolean, Optional optHabil As String = "", Optional sinCobrador As Boolean = False)
    Dim i As Integer
    Me.consulta optHabil, sinCobrador
    i = 0
    cajaList.Clear
    If conCodigo Then
        While orset.CanMoveNext
            cajaList.AddItem arreglanum2dig(Me.codigo) & " - " & nombre
            cajaList.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    Else
        While orset.CanMoveNext
            cajaList.AddItem nombre
            cajaList.ItemData(i) = codigo
            orset.MoveNext
            i = i + 1
        Wend
    End If
    'If cajaList.ListCount = 1 Then
    '    cajaList.ListIndex = 0
    'End If
    orset.CierraRec
End Sub
Public Sub llenaHGrid(Grid As MSHFlexGrid, Optional anchos As Variant, Optional titulos As Variant, Optional optHabil As String = "")
    Dim i As Integer
    With Grid
    'vacia el grid
        .Clear
    'setea numero de columnas y filas
        .Cols = 5
        .Rows = 2
    'coloca datos
        Me.consulta optHabil
        If orset.numRegistros > 0 Then
            Set .DataSource = orset.mrec
        End If
        orset.CierraRec
    'setea anchos
        If IsMissing(anchos) Then
            .ColWidth(0) = 40 * 15
            .ColWidth(1) = 150 * 15
            .ColWidth(2) = 40 * 15
        Else
            'jala anchos de la variable
            cambiaAnchosHFG Grid, anchos
        End If
    'coloca titulos
        If IsMissing(titulos) Then
            .TextMatrix(0, 0) = "Codigo"
            .TextMatrix(0, 1) = "Nombre"
            .TextMatrix(0, 2) = "Estado"
        Else
            'jala titulos de la variable
            cambiaTitulosHFG Grid, titulos
        End If
        .Row = 0
    End With
End Sub
Public Sub llenaGridSQL(Grid As MSHFlexGrid, sql_query As ClsSQL, Optional anchos As Variant, Optional titulos As Variant, Optional optHabil As String = "")
    Dim i As Integer
    With Grid
    'vacia el grid
        .Clear
    'coloca datos
        orset.AbreRec sql_query.cadena
        If orset.numRegistros > 0 Then
            Set .DataSource = orset.mrec
        Else
            'coloca un grid vacio
            .Rows = 2
        End If
        orset.CierraRec
    'setea anchos
        If IsMissing(anchos) Then
            For i = 0 To .Cols - 1
                .ColWidth(i) = 100 * 15
            Next
        Else
            'jala anchos de la variable
            cambiaAnchosHFG Grid, anchos
        End If
    'coloca titulos
        If IsMissing(titulos) Then
            For i = 0 To .Cols - 1
                .TextMatrix(0, i) = "Codigo"
            Next
        Else
            'jala titulos de la variable
            cambiaTitulosHFG Grid, titulos
        End If
        .Row = 1
    End With
End Sub

Private Sub orset_DataChanged()
    Reload_members
End Sub
